import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { User } from '@/entity/miniProgram/User';

@Entity()
// @Check(`"type" IN ('text', 'video')`)
export class KnowledgeClassroom {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  type: string;

  @Column({ default: 'knowledge' })
  channel: 'drug' | 'knowledge';

  @Column()
  url: string;

  @Column()
  title: string;

  @Column({ type: 'longtext' })
  content: string;

  @Column({ nullable: true })
  author: string;

  // 浏览量
  @Column({ default: 0 })
  view: number;

  // 收藏量
  @ManyToMany(() => User, (user) => user.collect_knowledge, {
    onDelete: 'CASCADE',
  })
  @JoinTable({ name: 'user_collect_knowledge' })
  collect_user: User[];

  @Column({ default: false })
  deleted: boolean;

  @CreateDateColumn()
  created: Date;

  @UpdateDateColumn()
  updated: Date;
}
